<template>
  <van-cell-group class="panel-rectify-filter">
    <van-cell>
      <van-dropdown-menu>
        <van-dropdown-item v-model="status" :options="statusOption" />
        <van-dropdown-item v-model="carrier" :options="carrierOption" />
      </van-dropdown-menu>
    </van-cell>
    <van-cell v-if="showFlag">
      <van-dropdown-menu>
        <van-dropdown-item  v-model="type" :options="getTypeOption" />
      </van-dropdown-menu>
    </van-cell>
  </van-cell-group>
</template>

<script>
import { getCarrierList } from '@/api/assess'

export default {
  name: 'PanelRectifyFilter',
  props: ['assessType', 'step', 'default'],
  data () {
    return {
      // status: (this.$route.query.dbstatus == 5 || this.$route.query.dbstatus == 8) ? 'rectify' : this.default,
      status: (this.$route.query.dbstatus == 2 || this.$route.query.dbstatus == 5) ? 'rectify' :  (this.$route.query.dbstatus == 4 || this.$route.query.dbstatus == 8) ? 'commit' : this.default,
      type: (this.$route.query.dbstatus == 5 || this.$route.query.dbstatus == 8) ? 'manage' : 'review',
      carrier: '',
      carrierOption: [
        { text: '全部载体', value: '' }
      ],
      typeOption: [
        { text: '安监部门审核角色', value: 'review' },
        { text: '专业部门审核角色', value: 'manage' }
      ],
      wcon:true
    }
  },
  mounted () {
    getCarrierList(this.$vo.CarrierType.SUB).then(res => {
      let { data } = res
      if (data[this.$response.CODE] === this.$response.SUCCESS) {
        let str = JSON.stringify(data[this.$response.DATA].check_list.sort(this.listSort)).replace(new RegExp('id', 'g'), 'value').replace(new RegExp('item', 'g'), 'text')
        this.carrierOption = this.carrierOption.concat(JSON.parse(str))
      }
    }, errFunc => {
      this.$notify('服务调用失败：' + errFunc.toString())
      console.log(errFunc.toString())
    })

 
  },
  methods: {
    doSelected () {
      let select = {}
      select.carrier = this.carrier 
      select.status =  this.status
      select.type = this.type
      this.$emit('onSelect', select)
    }
  },
  computed: {
    statusOption: function () {
      let obj = []
      if (this.assessType === this.$vo.AssessType.CORP + '') {
        obj = [
          { text: '所有整改', value: '' },
          { text: '问题未处理', value: this.$vo.RectStatus.INIT + '' },
          { text: '整改已通知', value: this.$vo.RectStatus.TASK + '' },
          { text: '措施已制定', value: this.$vo.RectStatus.PLAN + '' },
          { text: '措施已审核', value: this.$vo.RectStatus.APPR + '' },
          { text: '措施已落实', value: this.$vo.RectStatus.EXEC + '' },
          { text: '整改已验收', value: this.$vo.RectStatus.ACCE + '' }
        ]
      } else {
        obj = [
          { text: '所有整改', value: '' },
          { text: '问题未处理', value: this.$vo.RectStatus.INIT + '' },
          { text: '整改已通知', value: this.$vo.RectStatus.TASK + '' },
          { text: '措施已制定', value: this.$vo.RectStatus.PLAN + '' },
          { text: '专业部门已审核', value: this.$vo.RectStatus.PRE_APPR + '' },
          { text: '安监部门已审核', value: this.$vo.RectStatus.APPR + '' },
          { text: '措施已落实', value: this.$vo.RectStatus.EXEC + '' },
          { text: '专业部门已验收', value: this.$vo.RectStatus.PRE_ACCE + '' },
          { text: '安监部门已验收', value: this.$vo.RectStatus.ACCE + '' }
        ]
      }
      return obj
    },
    showFlag: function () {
      let flag = false
      if (this.assessType === this.$vo.AssessType.CORP + '') {
        return flag
      }
      switch (this.step) {
        case this.$vo.RectStep.APPR:
        case this.$vo.RectStep.ACCE:
          flag = true
          break
      }
      return flag
    },
    getTypeOption: function () {
      if (this.step === this.$vo.RectStep.APPR) {
        return [
          { text: '安监部门审核角色', value: 'review' },
          { text: '专业部门审核角色', value: 'manage' }
        ]
      }

      if (this.step === this.$vo.RectStep.ACCE) {
        return [
          { text: '安监部门验收角色', value: 'review' },
          { text: '专业部门验收角色', value: 'manage' }
        ]
      }

      return []
    }
  },
  watch: {
    status: function () {
      this.doSelected()
    },
    type: function () {
      this.doSelected()
    },
    carrier: function () {
      this.doSelected()
    }
  }
}
</script>

<style scoped lang="less">
.panel-rectify-filter{
  /deep/ .van-ellipsis {
    font-size: 14px;
  }
  .van-cell{
    height: 50px;
    line-height: 20px;
    padding: 4px 16px;
  }
  .unselect {
    /deep/ .van-dropdown-menu__title {
      color: #969799;
    }
  }
}
</style>
